
import {Image, Text} from "react-native";
import React from "react";

export const faces = [{
    "name": "[表情1]",
    "resource": require("../../resource/face/1.gif")
}, {
    "name": "[表情2]",
    "resource": require("../../resource/face/2.gif")
}, {
    "name": "[表情3]",
    "resource": require("../../resource/face/3.gif")
}, {
    "name": "[表情4]",
    "resource": require("../../resource/face/4.gif")
}, {
    "name": "[表情5]",
    "resource": require("../../resource/face/5.gif")
}, {
    "name": "[表情6]",
    "resource": require("../../resource/face/6.gif")
}, {
    "name": "[表情7]",
    "resource": require("../../resource/face/7.gif")
}, {
    "name": "[表情8]",
    "resource": require("../../resource/face/8.gif")
}, {
    "name": "[表情9]",
    "resource": require("../../resource/face/9.gif")
}, {
    "name": "[表情10]",
    "resource": require("../../resource/face/10.gif")
}, {
    "name": "[表情11]",
    "resource": require("../../resource/face/11.gif")
}, {
    "name": "[表情12]",
    "resource": require("../../resource/face/12.gif")
}, {
    "name": "[表情13]",
    "resource": require("../../resource/face/13.gif")
}, {
    "name": "[表情14]",
    "resource": require("../../resource/face/14.gif")
}, {
    "name": "[表情15]",
    "resource": require("../../resource/face/15.gif")
}, {
    "name": "[表情16]",
    "resource": require("../../resource/face/16.gif")
}, {
    "name": "[表情17]",
    "resource": require("../../resource/face/17.gif")
}, {
    "name": "[表情18]",
    "resource": require("../../resource/face/18.gif")
}, {
    "name": "[表情19]",
    "resource": require("../../resource/face/19.gif")
}, {
    "name": "[表情20]",
    "resource": require("../../resource/face/20.gif")
}, {
    "name": "[表情21]",
    "resource": require("../../resource/face/21.gif")
}, {
    "name": "[表情22]",
    "resource": require("../../resource/face/22.gif")
}, {
    "name": "[表情23]",
    "resource": require("../../resource/face/23.gif")
}, {
    "name": "[表情24]",
    "resource": require("../../resource/face/24.gif")
}, {
    "name": "[表情25]",
    "resource": require("../../resource/face/25.gif")
}, {
    "name": "[表情26]",
    "resource": require("../../resource/face/26.gif")
}, {
    "name": "[表情27]",
    "resource": require("../../resource/face/27.gif")
}, {
    "name": "[表情28]",
    "resource": require("../../resource/face/28.gif")
}, {
    "name": "[表情29]",
    "resource": require("../../resource/face/29.gif")
}, {
    "name": "[表情30]",
    "resource": require("../../resource/face/30.gif")
}, {
    "name": "[表情31]",
    "resource": require("../../resource/face/31.gif")
}, {
    "name": "[表情32]",
    "resource": require("../../resource/face/32.gif")
}, {
    "name": "[表情33]",
    "resource": require("../../resource/face/33.gif")
}, {
    "name": "[表情34]",
    "resource": require("../../resource/face/34.gif")
}, {
    "name": "[表情35]",
    "resource": require("../../resource/face/35.gif")
}, {
    "name": "[表情36]",
    "resource": require("../../resource/face/36.gif")
}, {
    "name": "[表情37]",
    "resource": require("../../resource/face/37.gif")
}, {
    "name": "[表情38]",
    "resource": require("../../resource/face/38.gif")
}, {
    "name": "[表情39]",
    "resource": require("../../resource/face/39.gif")
}, {
    "name": "[表情40]",
    "resource": require("../../resource/face/40.gif")
}, {
    "name": "[表情41]",
    "resource": require("../../resource/face/41.gif")
}, {
    "name": "[表情42]",
    "resource": require("../../resource/face/42.gif")
}, {
    "name": "[表情43]",
    "resource": require("../../resource/face/43.gif")
}, {
    "name": "[表情44]",
    "resource": require("../../resource/face/44.gif")
}, {
    "name": "[表情45]",
    "resource": require("../../resource/face/45.gif")
}, {
    "name": "[表情46]",
    "resource": require("../../resource/face/46.gif")
}, {
    "name": "[表情47]",
    "resource": require("../../resource/face/47.gif")
}, {
    "name": "[表情48]",
    "resource": require("../../resource/face/48.gif")
}, {
    "name": "[表情49]",
    "resource": require("../../resource/face/49.gif")
}, {
    "name": "[表情50]",
    "resource": require("../../resource/face/50.gif")
}, {
    "name": "[表情51]",
    "resource": require("../../resource/face/51.gif")
}, {
    "name": "[表情52]",
    "resource": require("../../resource/face/52.gif")
}, {
    "name": "[表情53]",
    "resource": require("../../resource/face/53.gif")
}, {
    "name": "[表情54]",
    "resource": require("../../resource/face/54.gif")
}, {
    "name": "[表情55]",
    "resource": require("../../resource/face/55.gif")
}, {
    "name": "[表情56]",
    "resource": require("../../resource/face/56.gif")
}, {
    "name": "[表情57]",
    "resource": require("../../resource/face/57.gif")
}, {
    "name": "[表情58]",
    "resource": require("../../resource/face/58.gif")
}, {
    "name": "[表情59]",
    "resource": require("../../resource/face/59.gif")
}, {
    "name": "[表情60]",
    "resource": require("../../resource/face/60.gif")
}, {
    "name": "[表情61]",
    "resource": require("../../resource/face/61.gif")
}, {
    "name": "[表情62]",
    "resource": require("../../resource/face/62.gif")
}, {
    "name": "[表情63]",
    "resource": require("../../resource/face/63.gif")
}, {
    "name": "[表情64]",
    "resource": require("../../resource/face/64.gif")
}, {
    "name": "[表情65]",
    "resource": require("../../resource/face/65.gif")
}, {
    "name": "[表情66]",
    "resource": require("../../resource/face/66.gif")
}, {
    "name": "[表情67]",
    "resource": require("../../resource/face/67.gif")
}, {
    "name": "[表情68]",
    "resource": require("../../resource/face/68.gif")
}, {
    "name": "[表情69]",
    "resource": require("../../resource/face/69.gif")
}, {
    "name": "[表情70]",
    "resource": require("../../resource/face/70.gif")
}, {
    "name": "[表情71]",
    "resource": require("../../resource/face/71.gif")
}, {
    "name": "[表情72]",
    "resource": require("../../resource/face/72.gif")
}, {
    "name": "[表情73]",
    "resource": require("../../resource/face/73.gif")
}, {
    "name": "[表情74]",
    "resource": require("../../resource/face/74.gif")
}, {
    "name": "[表情75]",
    "resource": require("../../resource/face/75.gif")
}, {
    "name": "[表情76]",
    "resource": require("../../resource/face/76.gif")
}, {
    "name": "[表情77]",
    "resource": require("../../resource/face/77.gif")
}, {
    "name": "[表情78]",
    "resource": require("../../resource/face/78.gif")
}, {
    "name": "[表情79]",
    "resource": require("../../resource/face/79.gif")
}, {
    "name": "[表情80]",
    "resource": require("../../resource/face/80.gif")
}, {
    "name": "[表情81]",
    "resource": require("../../resource/face/81.gif")
}, {
    "name": "[表情82]",
    "resource": require("../../resource/face/82.gif")
}, {
    "name": "[表情83]",
    "resource": require("../../resource/face/83.gif")
}, {
    "name": "[表情84]",
    "resource": require("../../resource/face/84.gif")
}, {
    "name": "[表情85]",
    "resource": require("../../resource/face/85.gif")
}, {
    "name": "[表情86]",
    "resource": require("../../resource/face/86.gif")
}, {
    "name": "[表情87]",
    "resource": require("../../resource/face/87.gif")
}, {
    "name": "[表情88]",
    "resource": require("../../resource/face/88.gif")
}];

export const  facesUtils = (function () {
    // 转化[xx]文字为图片
    var REGEX_RULE = /\[([^\]]+)\]/g;

    function convertToResource(text) {
        return text.replace(REGEX_RULE, function (res, val, index) {
            var targetResource = faces.filter(function (v) {
                return v.name === '[' + val + ']';
            });
            if (targetResource.length === 0) {
                return;
            }
            var targetResourceName = targetResource[0].name.replace('[', '').replace(']', '');
            return "<img class='face-image-content' src='static/dist/face/" + targetResource[0].resource + "' alt='" + targetResourceName + "'>";
        });
    }

    function convertToReactNativeResource(text) {
        // 替换表情
        const REGEX_RULE = /\[([^\]]+)\]/g;
        return text.split(REGEX_RULE).map((item)=>{
            if(!item){
                return ;
            }
            const targetResource = faces.filter(function (vv) {
                return vv.name === `[${item}]`;
            });
            // 文本
            if (targetResource.length === 0) {
                return <Text style={{fontSize:15,justifyContent:'flex-start',alignItems:'baseline'}} key={item}>{item}</Text>;
            }
            else {
                return <Image key={`[${item}]`} style={{position:'relative', top:1, width: 16, height: 16, justifyContent:'flex-start',alignItems:'baseline'}} source={targetResource[0].resource} />
            }
        });
    }

    return {
        convertToResource: convertToResource,
        convertToReactNativeResource: convertToReactNativeResource,
    }
})();
